<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/12/1 0001
  Time: 下午 4:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>我要还车</title>
    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/common.css">
    <style>
        .search{
            padding: 20px;
        }
    </style>
</head>
<body>
<div class="wrap-padding-15">
    <div class="search" style="margin-top: 10px">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-md1">
                <div class="layui-form-item">
                    <label class="layui-form-label">订单号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="orderid"  id="orderidd"  autocomplete="off" placeholder="请输入订单号">
                    </div>
                </div>
            </div>
            <div class="layui-col-md1 layui-col-md-offset2">
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn" id="search">查询</button>
                    </div>
                </div>

            </div>
        </div>

    </div>
    <div class="box-form layui-hide" id="returnMsg">
        <form class="layui-form "  method="post"  id="formid">

            <input type="hidden" name="orderid"  id="orderid">
            <input type="hidden" name="orderstate"  id="orderstate" value="3">
            <div class="layui-form-item">
                <label class="layui-form-label">品牌型号：</label>
                <div class="layui-input-block">
                    <input type="text" name="carbrand"  id="carbrand" autocomplete="off" class="layui-input" value="${cars.carbrand}">
                    <input type="hidden" name="carid" id="carid" value="${cars.carid}">
                    <input type="hidden" name="carcode" id="carcode" value="${cars.carcode}">
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">车辆图片:</label>
                <div class="layui-input-block">
                    <div class="layui-upload">
                        <button type="button" class="layui-btn" id="upload"></button>
                        <input type="hidden" name="picture" id="picture" value="">
                        <div class="layui-upload-list">
                            <img class="layui-upload-img" STYLE="width: 100px;height: 100px" id="demo1"  >
                            <p id="uploadMsg" ></p>
                        </div>
                    </div>
                </div>
            </div>


            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                <legend>取车地</legend>
            </fieldset>

            <div  class="layui-form-item ">
                <label class="layui-form-label">取车门店：</label>
                <div class="layui-input-block">
                    <input type="text" name="btrentdept" id="btrentdept" value="${carOrder.btrentdept}" autocomplete="off" class="layui-input"/>
                </div>
            </div>

            <div  class="layui-form-item ">
                <label class="layui-form-label">取车时间：</label>
                <div class="layui-input-block">
                    <input type="text" name="readybttime"  id="readybttime"  autocomplete="off" class="layui-input"  value="<fmt:formatDate value="${carOrder.readybttime}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate>"/>
                </div>
            </div>

            <div  class="layui-form-item ">
                <label class="layui-form-label">详细地址：</label>
                <div class="layui-input-block">
                    <input type="text" name="rentDetailAddress" id="rentDetailAddress" value="${carOrder.btrentdept}" autocomplete="off" class="layui-input"/>
                </div>
            </div>

            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                <legend>还车地</legend>
            </fieldset>

            <div  class="layui-form-item ">
                <label class="layui-form-label">还车门店：</label>
                <div class="layui-input-block">
                    <input type="text" name="etrentdept"  id="etrentdept" value="${carOrder.etrentdept}"  autocomplete="off" class="layui-input"/>
                </div>
            </div>

            <div  class="layui-form-item ">
                <label class="layui-form-label">还车时间：</label>
                <div class="layui-input-block">
                    <input type="text" name="readettime" id="readettime"  autocomplete="off" class="layui-input" value="<fmt:formatDate value="${carOrder.readettime}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate>"/>
                </div>
            </div>

            <div  class="layui-form-item ">
                <label class="layui-form-label">详细地址：</label>
                <div class="layui-input-block">
                    <input type="text" name="returnDetailAddress" id="returnDetailAddress" value="${carOrder.etrentdept}" autocomplete="off" class="layui-input"/>
                </div>
            </div>

            <div  class="layui-form-item ">
                <label class="layui-form-label">租期：</label>
                <div class="layui-input-block">
                    <input type="text" name="rentDay"  id="rentDay" autocomplete="off" class="layui-input" />
                    <input type="hidden" name="dayprice"  id="dayprice" value="${cars.dayprice}" autocomplete="off" class="layui-input" />
                </div>
            </div>




            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                <legend>费用明细:</legend>
            </fieldset>

            <div  class="layui-form-item ">
                <label class="layui-form-label">租赁费用：</label>
                <div class="layui-input-block">
                    <input type="text" name="shouldrent" id="shouldrent"  autocomplete="off" class="layui-input"/>
                </div>
            </div>

            <div  class="layui-form-item ">
                <label class="layui-form-label">基本保险：</label>
                <div class="layui-input-block">
                    <input type="text" name="shouldbasic" id="shouldbasic" value="${carOrder.shouldbasic}"   autocomplete="off" class="layui-input"/>
                </div>
            </div>


            <div  class="layui-form-item ">
                <label class="layui-form-label">总计：</label>
                <div class="layui-input-block">
                    <input type="text" name="shouldtotal" id="shouldtotal" value="${carOrder.shouldtotal}"    autocomplete="off" class="layui-input"/>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formSubmit">还车登记</button>

                </div>
            </div>
        </form>
    </div>
</div>

<script src="/static/plugins/jquery.js"></script>
<script src="/static/plugins/layui/layui.js"></script>
<script>

    layui.use(['upload','laydate','element','layer','form'], function() {
        var $ = layui.jquery
            , upload = layui.upload
            , laydate = layui.laydate
            , form = layui.form
            , element = layui.element
            , layer = layui.layer;
        //监听提交
        form.on('submit(formSubmit)',function (data) {
            $.ajax({
                url:"/carOrder/update",
                type:"post",
                dataType:"json",
                data:data.field,
                success:function (rs) {

                    if(rs.code==1){
                        layer.msg("车辆归还成功,审核中",{time:1000,icon:1},function () {
                            location.href = "/returncar"
                        })
                    }

                }
            })
            return false
        })


        $("#search").on('click',function (data) {
            var orderid = $("#orderidd").val()
            $.ajax({
                url:"/returncar/returnSearch",
                type:"get",
                data:{orderid:orderid},
                dataType:"json",
                success:function(msg){
                    if(msg.code==1){
                        $("#carbrand").val(msg.data[0].carbrand)
                        $("#carid").val(msg.data[0].carid)
                        $("#carcode").val(msg.data[0].carcode)
                        $("#btrentdept").val(msg.data[1].btrentdept)
                        $("#orderid").val(msg.data[1].orderid)
                        $("#readybttime").val(formatDate(new Date(msg.data[1].readybttime)))
                        $("#rentDetailAddress").val(msg.data[1].btrentdept)
                        $("#etrentdept").val(msg.data[1].etrentdept)
                        $("#readettime").val(formatDate(new Date(msg.data[1].readettime)))
                        $("#returnDetailAddress").val(msg.data[1].etrentdept)
                        $("#rentDay").val(Math.ceil((msg.data[1].readettime-msg.data[1].readybttime)/(1000*60*60*24))+"天")
                        $("#dayprice").val(msg.data[0].dayprice)
                        $("#shouldrent").val(msg.data[0].dayprice*(Math.ceil((msg.data[1].readettime-msg.data[1].readybttime)/(1000*60*60*60*24))))
                        $("#shouldbasic").val(msg.data[1].shouldbasic)
                        $("#shouldtotal").val(msg.data[1].shouldbasic+msg.data[0].dayprice*(Math.ceil((msg.data[1].readettime-msg.data[1].readybttime)/(1000*60*60*60*24))))

                        $("#returnMsg").removeClass("layui-hide")
                    }else{
                        layer.msg(msg.message,{time:1000,icon:2})
                    }
                },
                error:function () {
                }
            })

        })

        function   formatDate(now)   {
            var   year=now.getFullYear();
            var   month=now.getMonth()+1;
            var   date=now.getDate();
            var   hour=now.getHours();
            var   minute=now.getMinutes();
            var   second=now.getSeconds();
            debugger
            return   year+"-"+month+"-"+date+"   "+hour+":"+minute+":"+second;
        }

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#upload'
            , url: '/upload'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //上传成功
                if (res.code == 1){
                    $("#picture").val(res.data[0]);
                }
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    })

</script>
</body>
</html>
